<template>
	<view class="index">
		<!-- 轮播图 -->
		<swiper indicator-dots autoplay circular indicator-active-color="#fff">
			<swiper-item v-for="item in swipers" :key="item.id">
				<image :src="item.img"></image>
			</swiper-item>
		</swiper>
		<!-- 导航 -->
		<view class="nav">
			<navigator class="nav-item" v-for="(item,index) in navs" :key="index" :url="item.path">
				<view :class="item.icon"></view>
				<text>{{ item.title }}</text>
			</navigator>
		</view>
		<!-- 推荐商品 -->
		<view class="hot-goods">
			<view class="title">推荐商品</view>
			<!-- 商品列表 -->
			<goods-list :goods="goods"></goods-list>
		</view>
		
	</view>
</template>

<script>
	
	export default {
		data() {
			return {
				title: 'Hello',
				swipers:[],
				navs:[
					{
						title:'商品列表',
						icon:'iconfont icon-ziyuan',
						path:'/pages/goods/goods'
					},
					{
						title:'联系我们',
						icon:'iconfont icon-guanyuwomen',
						path:'/pages/contact/contact'
					},
					{
						title:'社区图片',
						icon:'iconfont icon-tupian',
						path:'/pages/pics/pics'
					},
					{
						title:'学习视频',
						icon:'iconfont icon-shipin',
						path:'/pages/videos/videos'
					}
				],
				goods:[]
			}
		},
		onLoad() {
			this.getSwipers()
			this.getHotGoods()
		},
		methods: {
			async getSwipers(){
				// this.$http({
				// 	url:'/api/getlunbo',
				// }).then(res => {
				// 	console.log(res);
				// })
				const res = await this.$http({
					url:'/api/getlunbo',
				})
				this.swipers = res
			},
			async getHotGoods(){
				const res = await this.$http({
					url:'/api/getgoods',
					data:{
						pageindex:1
					}
				})
				this.goods = res
			}
		}
	}
</script>

<style lang="scss" scoped>
.index{
	swiper{
		height: 380rpx;
		width: 100%;
		image{
			width: 100%;
			height: 100%;
		}
	}
	
	.nav{
		display: flex;
		justify-content: space-around;
	
		.nav-item{
			text-align: center;
			
			view{
				background-color: $shop-color;
				width: 120rpx;
				height: 120rpx;
				line-height: 120rpx;
				border-radius: 50%;
				margin: 20rpx auto;
				color: white;
				font-size: 50rpx;
			}
		}
	}
	
	.hot-goods{
		background-color: #eee;
		margin-top: 40rpx;
		overflow: hidden;
		
		.title{
			height: 100rpx;
			line-height: 100rpx;
			text-align: center;
			letter-spacing: 40rpx;
			font-size: 36rpx;
			color: $shop-color;
			background: white;
			margin: 8rpx 0;
		}
	}
}	
</style>
